package com.plan.service;

import com.plan.entity.School;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import com.plan.dao.UserDao;
import com.plan.entity.User;

import java.util.List;

@Transactional
@Service
public class UserServiceImpl implements UserService{
    @Autowired
    private UserDao userDao;

    @Override
    public User login(User user) {

        User userDB=userDao.findByUsername(user.getUsername());
        if(!ObjectUtils.isEmpty(userDB)){
            if(userDB.getPassword().equals(user.getPassword())){
                return userDB;
            }else{
                throw new RuntimeException("用户密码输入不正确");
            }
        }else{
            throw new RuntimeException("用户输入错误");
        }
    }

    @Override
    public User findUser(String id) {
        return userDao.findInfo(id);
    }

    @Override
    public List<School> search(String word, String word2, String word3) {
        return userDao.search(word,word2,word3);
    }
}
